<?php

namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Route;
use think\Db;

class Listc extends Controller
{

    public function index($id)
    {

//        echo 111;die;
        $res4=db('category')->where('pid',0)->field('id,cname')->select();

        $data=db('category')->where('id',$id)->find();
        $data1=db('category')->field('cname,id')->where('pid',$id)->select();
//        dump($data1);die;
        if (!empty($data1)){
            foreach ($data1 as $v )
            {
//            dump($v['id']);
                $data2['全部'][$v['cname']]=db('txt')->where('cid',$v['id'])->select();
            }
//        dump($data2);
            foreach ($data1 as $v )
            {
//            dump($v['id']);
                $data2['已完结'][$v['cname']]=db('txt')->where('cid',$v['id'])->where('end',1)->select();
            }
        }else{
            $data2=null;
        }


//        $data2['已完结'] = $data2;
//        $data2['未完结'] = $data3;
//        dump($data2['全部']);die;
//            $data3=Db::table('lamp_txt')
//                ->alias('txt')
//                ->join('lamp_category cate',"txt.cid=cate.id and txt.end = 0")
//                ->field('cate.cname,txt.id,txt.name,txt.desc,txt.photo,txt.zuozhe,txt.end,txt.addtime,txt.hot')
//                ->select();
//            dump($data2);die;
////
//$list =Db::field('*')->table('lamp_category c')->where('pid', $id)->join('lamp_txt t', 'c.id=t.cid')->select();
//dump($list);die;
//        $you = db('friendship')->where('status = 1')->select();
        return view('list/index',['data'=>$data,'data2'=>$data2,'data4'=>$res4]);
    }

}